import fetch from 'common/src/utils/fetch';

function findBclCultureOpen(data) {
    return fetch({
        url: '/api/cultureservice/BclCulturePlanOpen/findBclCultureOpen',
        method: 'post',
        data
    });
}

function insertCultureOpen(data) {
    return fetch({
        url: '/api/cultureservice/BclCulturePlanOpen/insertCultureOpen',
        method: 'post',
        data
    });
}

function updateCultureOpen(data) {
    return fetch({
        url: '/api/cultureservice/BclCulturePlanOpen/updateCultureOpen',
        method: 'post',
        data
    });
}

function findProfessionByDeptCode(data) {
    return fetch({
        url: '/api/baseresservice/campusProfession/findProfessionByDeptCode?' + spliceData(data),
        method: 'get'
    });
}

function findDepartMent(data) {
    return fetch({
        url: '/api/cultureservice/BclCulturePlanOpen/findDepartMent' + getParams(data),
        method: 'get'
    });
}

function deleteCultureOpen(data) {
    return fetch({
        url: '/api/cultureservice/BclCulturePlanOpen/deleteCultureOpen' + getParams(data),
        method: 'get'
    });
}

function getParams(params) {
    var paramsData = [];
    for (const key in params) {
        params[key] &&
            paramsData.push(
                key + '=' + params[key]
            );
    }
    if (paramsData.length)
        return '?' + paramsData.join('&');
    else
        return '';
}

function spliceData(params) {
    let str="";
    let keys =Object.keys(params);
    if(keys.length>0){
        keys.forEach((key,index)=>{
            if(index==keys.length-1){
                str+=`${key}=${params[key]?params[key]:""}`
            }else{
                str+=`${key}=${params[key]?params[key]:""}&`
            }
        })
    }
    return str;
}


const permissionApi = {
    'findBclCultureOpen': findBclCultureOpen,
    'insertCultureOpen': insertCultureOpen,
    'updateCultureOpen': updateCultureOpen,
    'findProfessionByDeptCode': findProfessionByDeptCode,
    'findDepartMent': findDepartMent,
    'deleteCultureOpen': deleteCultureOpen
}

export default permissionApi;